﻿
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Assignment3.Entities
{
    class SnowPlow : Entity
    {
        private GraphicsDevice _device;

        public SnowPlow(Camera camera, GraphicsDevice gd) : base(camera)
        {
            _device = gd;
        }

        public override void Draw()
        {
            _device.RasterizerState = RasterizerState.CullClockwise;

            foreach (ModelMesh mesh in Model.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    part.Effect = Effects["Basic"];

                    ((BasicEffect)Effects["Basic"]).Texture = Texture;
                    ((BasicEffect)Effects["Basic"]).TextureEnabled = true;

                    ((BasicEffect)Effects["Basic"]).World = ObjectWorld;
                    ((BasicEffect)Effects["Basic"]).View = Camera.View;
                    ((BasicEffect)Effects["Basic"]).Projection = Camera.Projection;

                    if (mesh.Name == "Circle.003" || mesh.Name == "Circle.004")
                    {
                        _device.BlendState = BlendState.AlphaBlend;
                        ((BasicEffect)Effects["Basic"]).Alpha = 0.5f;
                    }
                    else
                    {
                        _device.BlendState = BlendState.Opaque;
                        ((BasicEffect)Effects["Basic"]).Alpha = 1f;
                    }

                    part.Effect.CurrentTechnique.Passes[0].Apply();
                }
                mesh.Draw();
            }
            _device.RasterizerState = RasterizerState.CullCounterClockwise;

            foreach (ModelMesh mesh in Model.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    part.Effect = Effects["Basic"];

                    ((BasicEffect)Effects["Basic"]).Texture = Texture;
                    ((BasicEffect)Effects["Basic"]).TextureEnabled = true;

                    ((BasicEffect)Effects["Basic"]).World = ObjectWorld;
                    ((BasicEffect)Effects["Basic"]).View = Camera.View;
                    ((BasicEffect)Effects["Basic"]).Projection = Camera.Projection;

                    if (mesh.Name == "Circle.003" || mesh.Name == "Circle.004")
                    {
                        _device.BlendState = BlendState.AlphaBlend;
                        ((BasicEffect)Effects["Basic"]).Alpha = 0.5f;
                    }
                    else
                    {
                        _device.BlendState = BlendState.Opaque;
                        ((BasicEffect)Effects["Basic"]).Alpha = 1f;
                    }

                    part.Effect.CurrentTechnique.Passes[0].Apply();
                }
                mesh.Draw();
            }

            _device.BlendState = BlendState.Opaque;
            ((BasicEffect)Effects["Basic"]).Alpha = 1f;
        }

        public override void Update(GameTime gt)
        {
            Rotation *= Matrix.CreateRotationY(0.01f);
            base.Update(gt);
        }
    }
}
